package cn.fxzhang.leetcode.utils;

import cn.fxzhang.leetcode.common.TreeNode;

public class TreeNodeUtil {
    public static TreeNode buildTreeNode(Integer[] nums) {
        if (nums == null || nums.length == 0){
            return null;
        }
        return build(nums, 0);
    }

    private static TreeNode build(Integer[] nums, int i) {
        if (i >= nums.length || nums[i] == null){
            return null;
        }
        TreeNode root = new TreeNode(nums[i]);
        root.left = build(nums, i*2+1);
        root.right = build(nums, i*2+2);
        return root;
    }
}
